package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Sfzxjl;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class SfzxjlForm extends BasePage implements Serializable {
    private GenericManager<Sfzxjl, Long> sfzxjlManager;
    private Sfzxjl sfzxjl = new Sfzxjl();
    private Long id;

    public void setSfzxjlManager(GenericManager<Sfzxjl, Long> sfzxjlManager) {
        this.sfzxjlManager = sfzxjlManager;
    }

    public Sfzxjl getSfzxjl() {
        return sfzxjl;
    }

    public void setSfzxjl(Sfzxjl sfzxjl) {
        this.sfzxjl = sfzxjl;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        sfzxjlManager.remove(sfzxjl.getId());
        addMessage("sfzxjl.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            sfzxjl = sfzxjlManager.get(id);
        } else {
            sfzxjl = new Sfzxjl();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (sfzxjl.getId() == null || sfzxjl.getId() == 0);
        sfzxjlManager.save(sfzxjl);

        String key = (isNew) ? "sfzxjl.added" : "sfzxjl.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 